package com.ybdz.scanner.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ybdz.scanner.R;
import com.ybdz.scanner.bean.TakeTablesBean;
import com.ybdz.scanner.utils.UIUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ClassName: LookTakeAdapter
 * @author: zhao
 * @Description:    查看出库单的adapter
 * @date 2018/2/24 17:04
 */
public class LookTakeAdapter extends RecyclerView.Adapter {

    private List<TakeTablesBean.DataBean> data = new ArrayList<>();

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(UIUtils.getContext()).inflate(R.layout.item_recycleview, parent, false);
        return new LookDepositViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        LookDepositViewHolder viewHolder = (LookDepositViewHolder) holder;
        Integer quantity = data.get(position).getQuantity();
        Integer scanQuantity = data.get(position).getScanQuantity();
        if (quantity == scanQuantity){
            viewHolder.mTvWeight.setTextColor(UIUtils.getColor(R.color.gray));
            viewHolder.mTvName.setTextColor(UIUtils.getColor(R.color.gray));
            viewHolder.mTvConformity.setTextColor(UIUtils.getColor(R.color.gray));
        }
        viewHolder.mTvWeight.setText(data.get(position).getProductBatch());
        viewHolder.mTvName.setText(data.get(position).getContractNumber());
        viewHolder.mTvConformity.setText(data.get(position).getQuantity()+"");
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public void setData(List<TakeTablesBean.DataBean> data) {
        this.data = data;
    }


    static class LookDepositViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.tv_name)
        TextView mTvName;
        @BindView(R.id.tv_weight)
        TextView mTvWeight;
        @BindView(R.id.tv_conformity)
        TextView mTvConformity;

        LookDepositViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
